// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ILiveObjectContainer.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.LiveObjects.Interfaces
{
    #region Usings

    using System;

    using Org.OpenTrader.Framework.Enums;
    using Org.OpenTrader.Framework.Events;

    #endregion

    /// <summary>
    /// The interface live object container descriptor.
    /// </summary>
    public interface ILiveObjectContainerDescriptor
    {
        #region Properties

        /// <summary>
        /// Gets ID.
        /// </summary>
        Guid ID { get; }

        /// <summary>
        /// Gets Name.
        /// </summary>
        string Name { get; }

        /// <summary>
        /// Gets Registry.
        /// </summary>
        ILiveObjectsRegistry Registry { get; }

        /// <summary>
        /// Gets Resources.
        /// </summary>
        IResource[] Resources { get; }

        /// <summary>
        /// Gets Type.
        /// </summary>
        ELiveObjectContainerType Type { get; }

        /// <summary>
        /// Gets WorkingDirectory.
        /// </summary>
        string WorkingDirectory { get; }

        #endregion
    }

    /// <summary>
    /// The interface live object container.
    /// </summary>
    public interface ILiveObjectContainer : IRemotingStub
    {
        #region Properties

        /// <summary>
        /// All the objects
        /// </summary>
        Guid[] AllLiveObjects { get; }

        /// <summary>
        /// Gets AllTypes.
        /// </summary>
        string[] AllTypes { get; }

        /// <summary>
        /// The descriptor associated with this container
        /// </summary>
        ILiveObjectContainerDescriptor Descriptor { get; }

        /// <summary>
        /// Handler
        /// </summary>
        RemotableEventHandler<LiveObjectsEventArgs> LiveObjectsEventCB { get; }

        #endregion

        #region Public Methods

        /// <summary>
        /// Create an instance using given instanceDescriptor
        /// </summary>
        /// <typeparam name="T">
        /// </typeparam>
        /// <param name="instanceDescriptor">
        /// </param>
        /// <returns>
        /// </returns>
        T CreateLiveObject<T>(ILiveObjectDescriptor instanceDescriptor) where T : ILiveObject;

        /// <summary>
        /// Executed when destroying
        /// </summary>
        void Destroy();

        /// <summary>
        /// The attributes.
        /// </summary>
        /// <param name="typeName">
        /// The typeName.
        /// </param>
        /// <returns>
        /// </returns>
        Attribute[] GetAttributes(string typeName);

        /// <summary>
        /// The get configuration schema.
        /// </summary>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        /// <param name="schemaName">
        /// The schema name.
        /// </param>
        /// <returns>
        /// </returns>
        IConfigurationSchema GetConfigurationSchema(string typeName, string schemaName);

        /// <summary>
        /// The get configuration schema.
        /// </summary>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        /// <returns>
        /// </returns>
        IConfigurationSchema GetConfigurationSchema(string typeName);

        /// <summary>
        /// The find assembly name.
        /// </summary>
        /// <param name="typeName">
        /// The typeName.
        /// </param>
        /// <returns>
        /// The find assembly name.
        /// </returns>
        string GetContainingAssemblyName(string typeName);

        /// <summary>
        /// The get enum values.
        /// </summary>
        /// <param name="enumTypeName">
        /// The enum type name.
        /// </param>
        /// <returns>
        /// </returns>
        string[] GetEnumValues(string enumTypeName);

        /// <summary>
        /// The interfaces.
        /// </summary>
        /// <param name="typeName">
        /// The typeName.
        /// </param>
        /// <returns>
        /// </returns>
        string[] GetImplementedInterfaces(string typeName);

        /// <summary>
        /// The implementors.
        /// </summary>
        /// <param name="interfaceName">
        /// The interfaceName.
        /// </param>
        /// <returns>
        /// </returns>
        string[] GetImplementors(string interfaceName);

        /// <summary>
        /// Find some instance using its Guid and cast it to interface type T
        /// </summary>
        /// <typeparam name="T">
        /// </typeparam>
        /// <param name="guid">
        /// </param>
        /// <returns>
        /// </returns>
        T GetLiveObject<T>(Guid guid) where T : ILiveObject;

        /// <summary>
        /// Find some object using its name and cast it to interface type T
        /// </summary>
        /// <typeparam name="T">
        /// </typeparam>
        /// <param name="name">
        /// </param>
        /// <returns>
        /// </returns>
        T GetLiveObject<T>(string name) where T : ILiveObject;

        /// <summary>
        /// Lookup all known instances registered under the interfaceType interface
        /// </summary>
        /// <param name="interfaceType">
        /// The interface type we're intested in
        /// </param>
        /// <returns>
        /// A list of all known instances Guids(which may be of any known type implementing interface)
        /// </returns>
        Guid[] GetLiveObjects(string interfaceType);

        /// <summary>
        /// Executed when the container is created
        /// </summary>
        /// <param name="desc">
        /// The desc.
        /// </param>
        void Initialize(ILiveObjectContainerDescriptor desc);

        /// <summary>
        /// The knows about type.
        /// </summary>
        /// <param name="typeName">
        /// The typeName.
        /// </param>
        /// <returns>
        /// The knows about type.
        /// </returns>
        bool KnowsAboutType(string typeName);

        #endregion
    }
}